/**
 * Created by hxpeng on 2017/3/24.
 */

(function () {
    'use strict';

    angular.module('App.common')
        .service("LocalStorageUtils",LocalStorageUtils)

    /**
     * 浏览器本地存储工具js
     * @param $window
     * @returns {{set: set, get: get, setObject: setObject, getObject: getObject}}
     * @constructor
     */
    function LocalStorageUtils($window) {
        return{
            //存储单个属性
            set :function(key,value){
                $window.localStorage[key]=value;
            },
            //读取单个属性
            get:function(key){
                return  $window.localStorage[key];
            },
            //存储对象，以JSON格式存储
            setObject:function(key,value){
                $window.localStorage[key]=JSON.stringify(value);
            },
            //读取对象
            getObject: function (key) {
                return JSON.parse($window.localStorage[key] || '{}');
            }
        }
    }
})();



